package com.taomu.app.zongchouhuli.moudle.mine.activity;

import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;

import com.taomu.app.zongchouhuli.R;
import com.taomu.app.zongchouhuli.framework.BaseActivity;
import com.taomu.app.zongchouhuli.framework.BasePresenter;
import com.taomu.app.zongchouhuli.http.res.ResSelectBankEntity;
import com.taomu.app.zongchouhuli.moudle.mine.adpter.SelectBankAdp;
import com.taomu.app.zongchouhuli.moudle.mine.contract.UserSelectBankContract;
import com.taomu.app.zongchouhuli.moudle.mine.contract.UserSpreadContract;
import com.taomu.app.zongchouhuli.moudle.mine.contract.impl.UserSelectBankPresenter;

import java.util.ArrayList;
import java.util.List;

public class UserSelectBankActivity extends BaseActivity<UserSelectBankContract.Presenter> implements UserSelectBankContract.View{

    private RecyclerView recy;

    private ImageView mBackIm;

    private SelectBankAdp mAdp;

    private String selectbank = "";
    @Override
    protected int getContentLayout() {
        return R.layout.activity_select_bank_view;
    }

    @Override
    protected void initView() {
        if(getIntent() != null){
            selectbank = getIntent().getStringExtra("bank");
        }
        mBackIm = findViewById(R.id.bind_bank_back_im);
        mAdp = new SelectBankAdp(this,selectbank);
        recy = findViewById(R.id.select_bank_recy);
        recy.setLayoutManager(new LinearLayoutManager(this));
        recy.setAdapter(mAdp);
        mPresenter.getSelectBanks();
    }

    @Override
    protected void initData() {
//        List<String> data = new ArrayList<>();
//        for(int i=1;i<11;i++){
//            data.add("测试银行::::::"+String.valueOf(i));
//        }
//        mAdp.setData(data);
    }

    @Override
    protected void initEvent() {
        mBackIm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        mAdp.setSelectBankListener(new SelectBankAdp.SelectBankListener() {
            @Override
            public void onItemClick(String bank) {
                Intent intent = new Intent();
                intent.putExtra("bank",bank);
                setResult(0x65,intent);
                finish();
            }
        });
    }

    @Override
    protected UserSelectBankContract.Presenter createPresenter() {
        return new UserSelectBankPresenter(this);
    }

    @Override
    public void setBanks(ResSelectBankEntity resProductEntities) {
        if(resProductEntities.getData() != null){
            List<String> banks = new ArrayList<>();
            for(int i=0;i<resProductEntities.getData().size();i++){
                banks.add(resProductEntities.getData().get(i).getBank_name());
            }
            mAdp.setData(banks);
        }
    }

    @Override
    public void setPresenter(UserSelectBankContract.Presenter presenter) {

    }
}
